*WHAT'S ACROSS THE BORDER?
*JHA, NEUMARK, AND RODRIGUEZ-LOPEZ

* COUNTY FILE FOR 20 INDUSTRIES

include directories_build.do


* Load data at the czone-state-industry level
use "`cbpdir'`s'cbp_county_1990_2016", clear

merge m:1 sic87dd using "`cbpdir'`s'cbp_sic87dd_sic87ss_sic87xx_desc.dta"
keep if _merge==3
drop _merge 
drop if year==.

collapse (sum) emp est qp1  ap  (first) sic87xx_desc, by(cty_fips sic87xx year)

* Merge czone-state, multi data

	merge m:1 cty_fips using "`czonedir'`s'cty_czone_state_boundaries.dta", keep(1 3) generate(czone_merge)


	* Drop Alaska (FIPS state code 2, CZs 34101 to 34115)
	assert cty_fips >= 2000 & cty_fips <= 2999 if czone_merge == 1
	assert cty_fips >= 2000 & cty_fips <= 2999 if czone >= 34101 & czone <= 34115
	assert (czone >= 34101 & czone <= 34115) | (czone == .) if (cty_fips >= 2000 & cty_fips <= 2000)
	drop if cty_fips >= 2000 & cty_fips <= 2999

	* Drop Hawaii (FIPS state code 15, CZs 35600 and 34701-34703)
	assert cty_fips >= 15000 & cty_fips <= 15999 if czone == 35600 | (czone >= 34701 & czone <= 34703)
	drop if czone == 35600 | (czone >= 34701 & czone <= 34703)

	compress 
	
	

merge m:1 year cty_fips using "`popdir'`s'cty_pop_1990_2018.dta"
keep if _merge==3
drop _merge 
drop if year==.

merge m:1 czone using "`czonedir'`s'cw_czone_region_AADHP.dta"
keep if _merge==3
drop _merge 
drop if year==.

save "`cbpdir'`s'cbp_county_state_wages_20ind_1990_2016.dta", replace
